import threading
import time
class Mythread(threading.Thread):
    def run(self):
        if semaphore.acquire():
            print(self.name,time.ctime())
            time.sleep(3)
            semaphore.release()
if __name__=="__main__":
    ''' 信号量也是一个锁、设置最大允许进入线程数量 不设置默认为1'''
    semaphore = threading.Semaphore(10)
    ths=[]
    for i in range(100):
        ths.append(Mythread())
    for t in ths:
        t.start()
    t.join()
    print("over ended ")